<?php

class User_Controller_Admin_Manage extends Controller
{

	public function indexAction()
	{
		$table = Nuo::getTable('user@user');

		$tableRoleName = Nuo::getTableName('core_roles');
		$tableUserName = Nuo::getTableName('users');

		$select = $table -> select() -> from("$tableUserName", "$tableUserName.*") -> setIntegrityCheck(false) -> joinLeft($tableRoleName, "$tableRoleName.role_id=$tableUserName.role_id", array("$tableRoleName.role"));

		$this -> paginator = $paginator = Zend_Paginator::factory($select);

		$paginator -> setCurrentPageNumber($this -> _request -> getParam('page', 1));

	}

	public function addAction()
	{
		$form = $this -> form = Nuo::getTable('core@form') -> getForm('user@admin.create');

		$request = $this -> getRequest();

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getValues();

			$table = Nuo::getTable('user@user');

			$user = $table -> fetchNew();

			$user -> setFromArray($data);

			$user -> creation_date = $user -> modification_date = date('Y-m-d H:i:s');
			$user -> setPassword($data['password']);

			$user -> save();
			$this -> redirect('admin/user/manage');
		}

		$this -> setScript('module/core/views/admin/edit.tpl');
	}

}
